package com.lebsh.floor.show.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;

public class ImageWithLoadIndicator extends Composite {

	private AppImageResource imageResource = GWT.create(AppImageResource.class);
	private FlexTable layout = new FlexTable();
	private Image loadIndicator;
	private Image image;
	
	public ImageWithLoadIndicator(ImageResource resource){
		initWidget(layout);
		image = new Image(resource);
		loadIndicator = new Image(imageResource.loader());
		layout.setWidget(0, 0, loadIndicator);
		layout.setWidget(1, 0, image);
		image.addLoadHandler(new LoadHandler() {
			
			@Override
			public void onLoad(LoadEvent event) {
				layout.removeCell(0, 0);
				loadIndicator.setVisible(false);
				
			}
		});
		
		}
}
